while True:
    inp = input().strip().split(',')
    inp = map(int, inp)
    #得到数组
    res = 0

    mdict=dict()
    for num in inp:
        if num not in mdict:
            mdict[num]=1
        else:
            mdict[num]+=1

    vardict=mdict.copy()
    while max(mdict.values())>1:
        for k in mdict:
            if mdict[k]>=2:
                #修改字典
                vardict[k]-=1
                if k+1 not in mdict:
                    vardict[k+1]=1
                else:
                    vardict[k+1]+=1
                #操作数加一
                res += 1
        mdict=vardict.copy()
    print(res)